package com.apes.fn.tms.repository;

import com.apes.fn.tms.model.*;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface CarInformationRepository extends CustomRepository<CarInformation, String> {

    List<CarInformation> findAllByChauffeurIdAndStatus(Chauffeur chauffeur,String status);
    List<CarInformation> findAllByVehicleIdAndStatus(Vehicle vehicle, String status);
    List<CarInformation> findAllByStatus(String status);

    @Query(value = "SELECT t.* from TMS_CAR_DETAILS t where t.car_infomation_id = :carInformation",nativeQuery = true)
    List<CarDetails> findAllByCarInformationId(@Param("carInformation") CarInformation carInformation);

    @Query(value = " select t.* from tms_car_information t where t.id = ( " +
            " select t.car_infomation_id from TMS_CAR_DETAILS t where t.waybill_id = :waybill and t.status = :status)",nativeQuery = true)
    CarInformation findOneByWaybill(@Param("waybill")Waybill waybill,@Param("status")String status);


    @Query(value = "SELECT t.* from tms_car_information t where t.status = :status and t.create_date >= :startValue and t.create_date <= :endValue order by t.id desc",nativeQuery = true)
    List<CarInformation> findAllByStatusAndCreateDateAndDesc(@Param("status")String status, @Param("startValue") Date startValue, @Param("endValue")Date endValue);
}
